package com.kkb.retailer.center.controller;



import com.github.pagehelper.PageInfo;

import com.kkb.retailer.center.api.TemplateInfoService;
import com.kkb.retailer.center.common.http.HttpResult;
import com.kkb.retailer.center.common.pojo.TemplateInfo;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class TemplateController {

    @Reference
    private TemplateInfoService templateService;

    /**
     * 获取模板列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/getTemplateList")
    public HttpResult getTemplateList(@RequestParam(value="page",defaultValue="1")int pageNo, @RequestParam(value="pageSize",defaultValue="10")int pageSize){

        PageInfo<TemplateInfo> templates = templateService.getTemplate( pageNo+1, pageSize);
        return HttpResult.success(templates);
    }




    @GetMapping(value = "/getBrandsAndAttr")
    public HttpResult getBrandsAndAttr(Integer id){
        TemplateInfo templateInfo=templateService.getBrandsAndAttr(id);
        return HttpResult.success(templateInfo);
    }


    @PostMapping("/relatedBrand")
    public HttpResult templateRelatedBrand(@RequestBody TemplateInfo templateInfo){
        //根据传过来的模板id和brands字段中装的品牌数组字符串关联品牌，多了就增，少了就删
        System.out.println(templateInfo.getBrands());
        int result = templateService.updateTemplateInfo(templateInfo);
        return HttpResult.success(result);
    }

    @PostMapping("/relatedAttribute")
    public HttpResult templateRelatedAttr(@RequestBody TemplateInfo templateInfo){
        //根据传过来的模板id和Attribute字段中装的attribute数组字符串关联品牌，多了就增，少了就删
        System.out.println(templateInfo.getAttribute());
        int result = templateService.updateTemplateInfo(templateInfo);
        return HttpResult.success(result);
    }
}
